//
//  AppreciationViewController.m
//  Lovelife
//
//  Created by dllo on 15/4/21.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "AppreciationViewController.h"
#import "AppreciationButton.h"
#import "AppreciationListViewController.h"
#import "AppreciationCell.h"
#import "NightManager.h"
#define thereWidth self.view.frame.size.width / 3
#define thereHight self.view.frame.size.height / 4
@interface AppreciationViewController ()<UICollectionViewDataSource, UICollectionViewDelegate>
//@property(nonatomic, retain)AppreciationButton *scienceBu;
//@property(nonatomic, retain)AppreciationButton *carBu;
//@property(nonatomic, retain)AppreciationButton *buildBu;
//@property(nonatomic, retain)AppreciationButton *watchBu;
//@property(nonatomic, retain)AppreciationButton *wineBu;
//@property(nonatomic, retain)AppreciationButton *furnitureBu;
@property(nonatomic, retain)NSArray *photoArr;
@property(nonatomic, retain)NSArray *titleArr;
@property(nonatomic, retain)UICollectionViewFlowLayout *flow;
@property(nonatomic, retain)UICollectionView *collectoin;
@end

@implementation AppreciationViewController

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.photoArr = [NSArray array];
        self.titleArr = [NSArray array];
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"爱赏";
    self.view.backgroundColor = [UIColor whiteColor];
    //铺button
    UIImageView *backImageView = [[UIImageView alloc]initWithFrame:self.view.frame];
    backImageView.image = [UIImage imageNamed:@"aishang.jpg"];
    [self.view addSubview:backImageView];
    [backImageView release];
    
    self.titleArr = @[@"科技", @"赛车", @"建筑", @"手表", @"品味", @"家居"];
    self.photoArr = @[@"1.jpg",@"2.jpg", @"3.jpg", @"4.jpg", @"5.jpg", @"6.jpg"];
    
    self.flow = [[UICollectionViewFlowLayout alloc]init];
    self.flow.minimumInteritemSpacing = 0;
    self.flow.minimumLineSpacing = self.view.frame.size.height / 12;
    self.flow.scrollDirection = UICollectionViewScrollDirectionVertical;
    self.flow.itemSize = CGSizeMake(thereWidth, thereHight + 20);
    
    self.collectoin = [[UICollectionView alloc]initWithFrame:self.view.frame collectionViewLayout:self.flow];
    self.collectoin.backgroundColor = [UIColor whiteColor];
    [self.flow release];
    self.collectoin.delegate = self;
    self.collectoin.dataSource = self;
    [self.view addSubview:self.collectoin];
    [self.collectoin registerClass:[AppreciationCell class] forCellWithReuseIdentifier:@"reuse"];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 6;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    AppreciationCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"reuse" forIndexPath:indexPath];
    cell.photoImage.image = [UIImage imageNamed:self.photoArr[indexPath.row]];
    cell.titleLabel.text = self.titleArr[indexPath.row];
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    AppreciationListViewController *ALVC = [[AppreciationListViewController alloc]init];
    NSInteger nn = indexPath.row;
    ALVC.webID = nn+= 1;
    ALVC.nTitle = self.titleArr[indexPath.row];
    [self.navigationController pushViewController:ALVC animated:YES];
    [ALVC release];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)dealloc
{
    [_titleArr release];
    [_photoArr release];
    [_flow release];
    [_collectoin release];
    [super dealloc];
}

- (void)setLightDayModel
{
    [NightManager setBackgroundColorWithCollectionView:self.collectoin];
}

- (void)setNightDayModel
{
    [NightManager setBackgroundColorWithCollectionView:self.collectoin];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
